// TOWN SCRIPT
//    Town 4: Resistance Cave

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,choice;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
//Names

	set_name(6,"Suvar");
	set_name(7,"Olander");
	set_name(15,"Noland");
	set_name(14,"Andra");
	set_name(8,"Nablar");
	set_name(24,"Endora");

// Regenerate NPCs
// Klinger ID = 101
// Valzier ID = 300
spawn_creature(37);
spawn_creature(38);
if (get_sdf(110,0) == 10) {
 add_char_to_party(37);
 set_flag(110,0,1);
 print_str_color("Klinger is able to rest and rejoins the party!",3);
}
if (get_sdf(110,1) == 10) {
 add_char_to_party(38);
 set_flag(110,1,1);
 print_str_color("Valzier is able to rest and rejoins the party!",3);
}
erase_char(37);
erase_char(38);

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

if (get_sdf(1,10) < 3)
 set_terrain(58,24,0);

if (get_sdf(1,10) > 0)
 activate_hidden_group(1);

erase_char(39);
	
	set_crime_tolerance(3);

break;

beginstate EXIT_STATE;



break;

beginstate START_STATE;

if ((get_ran(1,0,100) < 7) && (get_attitude(6) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(6,"Arivan is strong.");
if ((get_ran(1,0,100) < 7) && (get_attitude(6) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(6,"We must proceed carefully.");

if ((get_ran(1,0,100) < 7) && (get_attitude(27) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(27,"She must be stopped.");
if ((get_ran(1,0,100) < 7) && (get_attitude(27) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(27,"Consult the scrolls.");

if ((get_ran(1,0,100) < 7) && (get_attitude(26) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(26,"We will be victorious.");
if ((get_ran(1,0,100) < 7) && (get_attitude(26) == 3) && (get_sdf(1,10) == 1))
		text_bubble_on_char(26,"We should attack soon.");

if ((get_ran(1,0,100) < 7) && (get_attitude(7) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(7,"Why do they do it?");
if ((get_ran(1,0,100) < 7) && (get_attitude(7) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(7,"Where do these ideas come from?");

if ((get_ran(1,0,100) < 7) && (get_attitude(8) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(8,"*whoosh*");
if ((get_ran(1,0,100) < 7) && (get_attitude(8) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(8,"*swoop*");

if ((get_ran(1,0,100) < 7) && (get_attitude(24) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(24,"Hmmmm...");
if ((get_ran(1,0,100) < 7) && (get_attitude(24) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(24,"I wonder if...");

if ((get_ran(1,0,100) < 7) && (get_attitude(15) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(15,"Yawn...");
if ((get_ran(1,0,100) < 7) && (get_attitude(15) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(15,"Nobody notices me.");

if ((get_ran(1,0,100) < 7) && (get_attitude(14) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(14,"Hmm, what are those?");
if ((get_ran(1,0,100) < 7) && (get_attitude(14) == 3) && (get_sdf(1,10) <= 2))
		text_bubble_on_char(14,"Interesting creatures...");


break;


beginstate 10;

if ((get_sdf(110,0) == 1) && (get_terrain(18,53) == 2)) {

relocate_character(4,19,53);
set_character_facing(4,0);
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(4,"Alzaba De Shah!");
force_instant_terrain_redraw();
play_sound(165);
pause(5);

text_bubble_on_char(4,"");
set_terrain(18,53,0);
set_terrain(19,53,0);
force_instant_terrain_redraw();
play_sound(163);
pause(5);

message_dialog("_We discovered these ancient alien ruins. The forcefield generators we found produce an illusion concealing our base. These alien weapons have been vital in our operations against Vikida._","");
}
else {
 set_terrain(18,53,0);
 set_terrain(19,53,0);
 force_instant_terrain_redraw();
}

break;


beginstate 11;

if (get_sdf(1,7) == 0) {
 set_flag(1,7,1);
 set_incidental_sound(1);
 play_sound(147);
 message_dialog("Amazing! You have never seen anything like this. These projectors are quite advanced, more so than a mere tribe of Nephil could ever hope to construct. This may explain why this island was so difficult to scry.","You wonder who, or what, created this.");
}

break;


beginstate 12;

set_incidental_sound(1);

if (get_sdf(1,8) == 0) {
 set_flag(1,8,1);
 message_dialog("Four Nephilim Archers await behind a sturdy stone wall. They seem quite surprised to see you. Klinger's presence, however, reassures them.","_These archers are merely token guards, greeters at the gate. The force fields are our real defense. If those fall, they would only be able to hold off an attack, not stop it._");
}

break;


beginstate 13;

if (get_sdf(1,9) == 0) {
 set_flag(1,9,1);
 message_dialog("_We must bring Chief Suvar the word that Asmur has fallen. He will not be pleased. However, these scrolls may give us an advantage, if they are as Lanthar said._","_Suvar essentially lives in the planning room. It is in the eastern building. He is truly great leader, but I suspect he is starting to run out of energy to lead our cause. Our fight tires him, and us all._");
}

break;


beginstate 14;

if (get_sdf(1,10) == 0) {

set_flag(1,10,1);

force_view_center(47,28);
text_bubble_on_char(6,"They are so many...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(6,"");
text_bubble_on_char(6,"...we are so few.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(6,"");
text_bubble_on_char(6,"Where next?");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(6,"");
relocate_character(4,47,32);
set_character_facing(4,0);
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(4,"Chieftain.");
relocate_character(4,47,31);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(4,"");
set_character_facing(6,4);
text_bubble_on_char(6,"Klinger!");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(6,"");
text_bubble_on_char(6,"You have returned.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(6,"");
relocate_character(5,46,32);
set_character_facing(5,0);
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(5,"Asmur brings a gift.");
relocate_character(5,46,31);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(5,"");
text_bubble_on_char(5,"Our history.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(5,"");
text_bubble_on_char(6,"Asmur?");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(6,"");
text_bubble_on_char(6,"Most peculiar...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(6,"");
text_bubble_on_char(4,"This is Valzier...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(4,"");
text_bubble_on_char(4,"...high shaman of Asmur.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(4,"");
text_bubble_on_char(4,"There is much to explain.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(4,"");
force_instant_terrain_redraw();
pause(2);

message_dialog("_Asmur has fallen to Arivan. We tried to warn them, but it was no use. Their defenses could not compare to her cruel forces. Within a few hours, the village and its people were no more._","_But, in its dying moments, we were able to secure a gift. They gave us several scrolls. Within are promised to be the secrets of the people of Asmur, secrets we have long sought._");

relocate_character(6,char_loc_x(6),char_loc_y(6) + 1);
force_instant_terrain_redraw();
pause(5);

message_dialog("_Bittersweet news indeed. Asmur was perhaps the last force in this forest besides us that could have stood up to Arivan. If only they had the will to do it. I must say I will never understand their ways._","");

pause(3);

message_dialog("Valzier responds. _Our ways are, were, our lessons from our history. We were once like Arivan, bent on the purification of the Nephil race. We overcame it, but at a great cost to our people._","_The idea of perfection is so contagious that we decided to isolate ourselves. Those who pondered it were banished. We tried our best to seal ourselves off. We wanted no part in it._");

pause(3);

message_dialog("Suvar replies angrily, _Then you should have known best to fight against it. Did you seriously think Arivan would leave you alone?_","");

pause(3);

message_dialog("Valzier returns passionately, _Fight? And then what? The idea of perfection is so strong, it cannot be stopped. Another movement will rise to take its place as it always has. You have heart, but not vision. Our history gave us wisdom._","");

pause(3);

message_dialog("The tension in the room is growing very thick that you can almost cut it with your swords. The disagreement between these two groups is like a festering blister that at last ruptured. Finally, Klinger interjects,","_Please. We are allies now. Perhaps they are right and another movement will rise. But now we have one out of control. It must be stopped now. The future can be dealt with later._");

pause(3);

message_dialog("With the tension relaxed, the room seems to cool substantially. Suvar sighs, _You're right Klinger. Valzier, let us see the scrolls. Any help you give will be useful to us._","");

relocate_character(4,char_loc_x(4),char_loc_y(4) + 1);
set_character_facing(4,4);
force_instant_terrain_redraw();
pause(5);

message_dialog("_We will now discuss new developments and plan our next move. You may rest here, in the quarters just to the west of this structure. The people here will help you as best they can._","");

force_view_center(char_loc_x(lead_char),char_loc_y(lead_char));
erase_char(character_in_party(101));
erase_char(character_in_party(300));
set_flag(110,0,5);
set_flag(110,1,5);
toggle_quest(3,0);
award_party_xp(200,5);
set_character_facing(6,2);
relocate_character(6,47,26);
activate_hidden_group(1);
force_instant_terrain_redraw();

}

break;


beginstate 15;

if (get_sdf(1,10) == 1) {
reset_dialog();
	add_dialog_str(0,"Klinger said you can rest on these beds. Nice accommodations, considering most of the Resistance sleeps on mere furs on the cave floor. The journey has been long and tiring. You can definitely use the sleep.",0);
	add_dialog_choice(0,"Take a rest.");
	add_dialog_choice(1,"Continue to look around.");
	choice = run_dialog(1);
 if (choice == 1) {
  revive_party();
  play_sound(20);
  set_state_continue(16);
  }
 if (choice == 2)
  block_entry(1);
}
else
 end();

break;


beginstate 16;

set_flag(1,10,2);

force_view_center(46,28);
set_total_visibility(1);
erase_text_bubbles();
force_instant_terrain_redraw();
pause(5);

message_dialog("Meanwhile, Suvar, Klinger, and Valzier are looking over the scrolls.","");
pause(5);

message_dialog("Suvar ponders, _There is so much here. It will take us much time to learn all this. Your knowledge of teleportation will be useful to us. We have an ancient teleporter we are perfecting._","_However, I find the notes on the Lost City to be most interesting. You call it 'the source of the power'. What does that mean, Valzier?_");
pause(5);

message_dialog("He shakes his head. _Only Lanthar saw our scrolls. I know not for sure. But there are some who believe, er...believed, that our advancement during those dark years was far too great and beyond natural._","");
pause(5);

message_dialog("_Beyond natural?_ Klinger asks.","");
pause(5);

message_dialog("Valzier shrugs. _Those theories were not very popular. They offended a certain sense of pride. Lanthar probably knew about it, but wanted no part of it. Going near could have spurred another movement._","_What we will find at the Lost City, I know not. The legends say there was a place before our movement. A place that went too far and summoned foul creatures. Now the city is haunted they say._");
pause(5);

message_dialog("Suvar muses, _It sounds risky. We have few to spare, and, if we look at the map,_ he puts his finger on the map and draws a line from the location of this base to the Lost City, _it is quite far._","");
pause(5);

message_dialog("Klinger interjects, _Perhaps we could use teleportation. There is a teleportation platform near there. It should not be too hard to focus on to it. Right, Valzier?_","");
pause(5);

message_dialog("Valzier nods. _Not at all. The platforms are good at that. So long as you get nearby, it will focus on the path to that destination._ Valzier explains how to target as best he can.","");
pause(5);

message_dialog("_But we cannot spare the people,_ warns Suvar.","");
pause(5);

message_dialog("_We have the outsiders,_ suggests Klinger. _They have shown themselves to be quite resourceful. Besides, even if we lose them, it is little consequence to us._","");
pause(5);

message_dialog("_But can they be trusted? We are putting a lot of faith in ones without the drive to be in our cause._","");
pause(5);

message_dialog("Klinger responds, _They have been trustworthy thus far. I will go with them, however, to ensure the rewards come to us and do not leave this forest._","");
pause(5);

message_dialog("_And I would like to accompany them. I would like to know more about this 'source' that my people believed in. It may be nothing, but I want to know,_ says Valzier.","");
pause(5);

message_dialog("Suvar thinks for a long time, weighing the options and performing the necessary calculus of risk involved. _We need every advantage we can have. Yes, we should go, and as soon as possible._","_Arivan is probably weak after attacking Asmur. If we can find new weapons, now would be the ideal time to use them against her._");
pause(5);

force_view_center(char_loc_x(0),char_loc_y(0));
set_total_visibility(0);
force_instant_terrain_redraw();
message_dialog("You take a nice rest in the accommodations set for you. You feel completely and utterly restored.","");

break;


beginstate 17;

if (get_attitude(6) == 3) {
 message_dialog("The guard blocks your passage. Whatever lies behind this door, you are not meant to see.","");
 block_entry(1);

}

break;


beginstate 18;

if ((get_sdf(1,10) < 3) && (get_attitude(6) == 3)) {
 message_dialog("The guard blocks your passage. Whatever lies behind this door, you are not meant to see.","");
 block_entry(1);

}

break;


beginstate 19;

message_dialog("The rune emits a forcefield. You have no way to disable it.","");
block_entry(1);

break;


beginstate 20;

if (get_terrain(58,24) == 270) {
message_dialog("The rune emits a forcefield blocking your, and everything else's, passage. It was quite hastily summoned, so it will not last long. However, it should give you sufficient time to escape.","");
block_entry(1);
}

break;


beginstate 21;

if (get_sdf(110,1) == 1) {
message_dialog("_Not this way! The teleporter is down the corridor to the west. The protective rune will not last for long, we do not have time for exploring!_","");
block_entry(1);
}

break;


beginstate 22;

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 0)) {
 set_flag(1,11,1);
 message_dialog("_The teleporter lies down the passage to the west. The ward emits a forcefield, but it will not hold for long. We shall not be safe until we reach the teleporter._","");
}

break;


beginstate 23;

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 1)) {
 set_flag(1,11,2);
 message_dialog("_Turn left here. We still have a ways to go and my rune is very temporary._","");
}

break;


beginstate 24;

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 2)) {
 set_flag(1,11,3);
 message_dialog("_Keep going straight. The teleporter is further to the west. The other corridors twist off into dead ends, and time we do not have. Whatever secrets they may hold, they must remain here._","");
}

break;


beginstate 25;

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 3)) {
 set_flag(1,11,4);
 message_dialog("_There should be a secret passage at the end of the corridor. The teleporter is not much farther from here. That's good. I sense not all goes well for our friends._","");
 set_state_continue(26);
}

break;


beginstate 26;

i = 6;
while (i < 35) {
 relocate_character(i,4,i - 2);
 set_character_pose(i,0);
 set_attitude(i,4);
 i = i + 1;
}

relocate_character(6,54,44);
relocate_character(26,54,45);
relocate_character(14,55,43);
relocate_character(7,53,44);
relocate_character(10,52,42);
relocate_character(11,54,42);
relocate_character(28,59,44);
relocate_character(29,60,44);
relocate_character(30,61,44);
relocate_character(31,62,44);
relocate_character(33,63,44);
set_character_facing(6,6);
set_character_facing(26,6);
set_character_facing(14,6);
set_character_facing(7,6);
set_character_facing(10,6);
set_character_facing(11,6);
set_character_facing(28,2);
set_character_facing(29,2);
set_character_facing(30,2);
set_character_facing(31,2);
set_character_facing(32,2);

set_total_visibility(1);
force_view_center(56,43);
force_instant_terrain_redraw();
pause(10);

relocate_character(28,58,44);
relocate_character(29,59,44);
relocate_character(30,60,44);
relocate_character(31,61,44);
relocate_character(33,62,44);
set_character_pose(28,2);
set_character_pose(29,2);
set_character_pose(30,2);
set_character_pose(31,2);
set_character_pose(33,2);
play_sound(18);
force_instant_terrain_redraw();
pause(5);

set_character_pose(26,2);
set_character_pose(14,2);
set_character_pose(7,2);
set_character_pose(10,2);
set_character_pose(11,2);
text_bubble_on_char(6,"Fall back!");
play_sound(18);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(6,"");
text_bubble_on_char(26,"We'll hold them back.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(26,"");
relocate_character(6,53,43);
set_character_facing(6,0);
relocate_character(28,57,43);
relocate_character(29,58,44);
relocate_character(30,59,44);
relocate_character(31,60,44);
relocate_character(33,61,44);
relocate_character(14,56,44);
set_character_facing(14,5);
set_character_pose(26,1);
play_sound(91);
force_instant_terrain_redraw();
pause(5);

put_effect_on_char(29,12,1,1);
run_animation_sound(98);
force_instant_terrain_redraw();
pause(1);

set_character_pose(29,11);
force_instant_terrain_redraw();
play_sound(31);
set_character_pose(29,12);
force_instant_terrain_redraw();
pause(1);
set_character_pose(29,13);
force_instant_terrain_redraw();
pause(1);
set_character_pose(29,14);
force_instant_terrain_redraw();
pause(1);

put_stain_on_space(char_loc_x(29),char_loc_y(29),2);
relocate_character(29,19,53);
set_character_pose(29,0);
set_character_pose(26,2);
relocate_character(30,58,44);
relocate_character(31,59,44);
relocate_character(33,60,44);
relocate_character(6,53,42);
relocate_character(10,52,41);
relocate_character(11,54,41);
force_instant_terrain_redraw();
pause(5);

i = 6;
while (i < 35) {
 relocate_character(i,4,i - 2);
 set_character_pose(i,0);
 set_attitude(i,4);
 i = i + 1;
}

relocate_character(28,45,34);
relocate_character(29,45,35);
relocate_character(30,45,36);
relocate_character(31,43,35);
relocate_character(32,43,36);
relocate_character(33,47,35);
relocate_character(34,48,36);
set_character_facing(28,6);
set_character_facing(29,6);
set_character_facing(30,6);
set_character_facing(31,6);
set_character_facing(32,6);
set_character_facing(33,0);
set_character_facing(34,0);
set_terrain(46,33,46);
set_terrain(47,33,46);
set_terrain(49,30,53);
set_terrain(49,31,53);
set_terrain(51,33,52);
set_terrain(52,33,52);
set_terrain(53,37,52);
set_terrain(58,28,53);
force_view_center(47,32);
force_instant_terrain_redraw();
pause(10);

set_character_pose(33,1);
put_boom_on_space(46,33,1,0);
put_boom_on_space(47,33,1,0);
set_terrain(46,33,0);
set_terrain(47,33,0);
set_terrain(46,32,137);
set_terrain(47,32,137);
set_terrain(46,31,138);
set_terrain(47,31,138);
run_animation_sound(5);
force_instant_terrain_redraw();
pause(10);

relocate_character(6,51,33);
relocate_character(10,52,33);
relocate_character(11,51,34);
relocate_character(28,49,30);
relocate_character(29,49,31);
relocate_character(30,48,31);
relocate_character(31,47,30);
relocate_character(32,47,31);
relocate_character(33,46,32);
relocate_character(34,47,32);
set_character_facing(6,0);
set_character_facing(10,0);
set_character_facing(11,0);
force_view_center(52,29);
force_instant_terrain_redraw();
pause(10);

relocate_character(6,51,33);
relocate_character(10,51,32);
relocate_character(11,52,32);
relocate_character(28,50,30);
relocate_character(29,50,31);
relocate_character(30,49,31);
relocate_character(31,48,30);
relocate_character(32,48,31);
relocate_character(33,46,31);
relocate_character(34,47,31);
set_character_facing(28,5);
set_character_facing(29,5);
set_character_facing(30,5);
set_character_facing(33,6);
set_character_facing(34,6);
set_character_pose(6,2);
set_character_pose(10,2);
set_character_pose(11,2);
set_character_pose(28,2);
set_character_pose(29,2);
set_character_pose(30,2);
set_character_pose(31,2);
set_character_pose(32,2);
set_character_pose(33,2);
set_character_pose(34,2);
play_sound(18);
force_instant_terrain_redraw();
pause(10);

set_character_pose(10,1);
put_effect_on_char(29,12,1,1);
run_animation_sound(70);
force_instant_terrain_redraw();
pause(1);

set_character_pose(29,11);
force_instant_terrain_redraw();
play_sound(31);
set_character_pose(29,12);
force_instant_terrain_redraw();
pause(1);
set_character_pose(29,13);
force_instant_terrain_redraw();
pause(1);
set_character_pose(29,14);
force_instant_terrain_redraw();
pause(1);

put_stain_on_space(char_loc_x(29),char_loc_y(29),2);
relocate_character(29,19,54);
set_character_pose(29,0);
set_character_pose(10,2);
force_instant_terrain_redraw();
pause(3);

relocate_character(30,50,31);
relocate_character(31,49,30);
relocate_character(32,49,31);
relocate_character(33,47,31);
relocate_character(34,48,31);
relocate_character(11,51,31);
set_character_facing(11,1);
force_instant_terrain_redraw();
pause(5);

set_character_pose(31,1);
play_sound(91);
force_instant_terrain_redraw();
pause(5);

put_effect_on_char(11,12,1,1);
run_animation_sound(98);
force_instant_terrain_redraw();
pause(1);

set_character_pose(11,11);
force_instant_terrain_redraw();
play_sound(31);
set_character_pose(11,12);
force_instant_terrain_redraw();
pause(1);
set_character_pose(11,13);
force_instant_terrain_redraw();
pause(1);
set_character_pose(11,14);
force_instant_terrain_redraw();
pause(1);

put_stain_on_space(char_loc_x(11),char_loc_y(11),2);
relocate_character(11,4,9);
set_character_pose(11,0);
set_character_pose(31,2);
force_instant_terrain_redraw();
pause(3);

set_character_pose(6,1);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(28),char_loc_y(28),0);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(30),char_loc_y(30),0);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(31),char_loc_y(31),0);
put_boom_on_char(28,0,0);
put_boom_on_char(30,0,0);
put_boom_on_char(31,0,0);
put_stain_on_space(char_loc_x(28),char_loc_y(28),6);
put_stain_on_space(char_loc_x(30),char_loc_y(30),6);
put_stain_on_space(char_loc_x(31),char_loc_y(31),6);
relocate_character(28,4,26);
relocate_character(30,4,28);
relocate_character(31,4,29);
run_animation_sound(51);
force_instant_terrain_redraw();
pause(1);

set_character_pose(6,2);
force_instant_terrain_redraw();
pause(3);

relocate_character(6,char_loc_x(6),char_loc_y(6) - 1);
relocate_character(10,char_loc_x(10),char_loc_y(10) - 1);
set_character_facing(6,2);

set_character_pose(33,1);
play_sound(74);
force_instant_terrain_redraw();
pause(2);

put_effect_on_char(10,1,1,1);
run_animation_sound(109);
force_instant_terrain_redraw();
pause(1);

set_character_pose(10,11);
force_instant_terrain_redraw();
play_sound(31);
set_character_pose(10,12);
force_instant_terrain_redraw();
pause(1);
set_character_pose(10,13);
force_instant_terrain_redraw();
pause(1);
set_character_pose(10,14);
force_instant_terrain_redraw();
pause(1);

put_stain_on_space(char_loc_x(10),char_loc_y(10),2);
relocate_character(10,4,8);
set_character_pose(10,0);
set_character_pose(33,2);
force_instant_terrain_redraw();
pause(3);

relocate_character(6,char_loc_x(6),char_loc_y(6) - 1);
set_character_facing(6,2);

set_character_pose(32,1);
play_sound(91);
force_instant_terrain_redraw();
pause(5);

put_effect_on_char(6,12,1,1);
run_animation_sound(98);
force_instant_terrain_redraw();
pause(1);

set_character_pose(32,2);
force_instant_terrain_redraw();
pause(3);

set_character_pose(6,1);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(32),char_loc_y(32),0);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(33),char_loc_y(33),0);
put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(34),char_loc_y(34),0);
put_boom_on_char(32,0,0);
put_boom_on_char(33,0,0);
put_boom_on_char(34,0,0);
put_stain_on_space(char_loc_x(32),char_loc_y(32),6);
put_stain_on_space(char_loc_x(33),char_loc_y(33),6);
relocate_character(32,4,30);
relocate_character(33,4,31);
run_animation_sound(51);
force_instant_terrain_redraw();
pause(1);

set_character_pose(6,2);
force_instant_terrain_redraw();
pause(3);

text_bubble_on_char(34,"Ack! Ughk!");
force_instant_terrain_redraw();
pause(10);

relocate_character(6,char_loc_x(6) - 1,char_loc_y(6));
text_bubble_on_char(34,"");
text_bubble_on_char(34,"Oh my!");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(34,"");
activate_hidden_group(3);
set_character_facing(36,3);
set_character_facing(6,7);
set_character_pose(36,2);
put_effect_on_char(36,8,8,0);
force_instant_terrain_redraw();
run_animation_sound(163);
pause(2);

set_character_pose(36,1);
set_character_pose(6,0);
put_jagged_zap(char_loc_x(36),char_loc_y(36),char_loc_x(6),char_loc_y(6),5);
set_char_status(6,29,1,1,0);
force_instant_terrain_redraw();
run_animation_sound(89);
pause(10);

set_character_pose(36,0);
set_character_pose(34,0);
relocate_character(36,char_loc_x(36) - 1,char_loc_y(36) + 1);
relocate_character(34,char_loc_x(34) + 1,char_loc_y(34));
force_instant_terrain_redraw();
pause(5);

set_character_pose(36,2);
relocate_character(36,char_loc_x(36) - 1,char_loc_y(36) + 1);
force_instant_terrain_redraw();
pause(5);

set_character_pose(36,2);
relocate_character(36,char_loc_x(36) - 1,char_loc_y(36) + 1);
set_character_facing(36,2);
force_instant_terrain_redraw();
pause(5);

set_character_facing(36,4);
set_character_facing(6,0);
text_bubble_on_char(36,"Ah, Suvar...");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(36,"");
text_bubble_on_char(36,"...at last, the inevitable.");
force_instant_terrain_redraw();
pause(15);

text_bubble_on_char(36,"");

i = 6;
while (i < 35) {
 relocate_character(i,4,i - 2);
 set_character_pose(i,0);
 i = i + 1;
}

force_view_center(char_loc_x(lead_char),char_loc_y(lead_char));
set_total_visibility(0);
force_instant_terrain_redraw();

break;


beginstate 27;

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 4)) {
 set_flag(1,11,5);
 message_dialog("_The secret passage is at the end of the wall. It's a clever illusion. Tough to find._","");
}

break;


beginstate 28;

if (get_sdf(1,11) == 3) {
 set_flag(1,11,5);
 message_dialog("_There should be a secret passage at the end of the corridor. The teleporter is not much farther from here. That's good. I sense not all goes well for our friends._","");
 block_entry(1);
 set_state_continue(26);
 end();
}

if ((get_sdf(110,1) == 1) && (get_sdf(1,11) == 5) && (is_combat() == 0)) {
 set_flag(1,11,6);
 message_dialog("You search the wall for a secret passage. You put your hand against every surface, each nook and cranny, looking for some indentation or switch, but to no avail. Despite your best efforts, you cannot find it.","");
 erase_char(character_in_party(421));
 activate_hidden_group(4);
 set_level(35,15);
 set_character_facing(0,6);
 set_character_facing(1,6);
 set_character_facing(2,6);
 set_character_facing(3,6);
 force_instant_terrain_redraw();
 pause(10);
 message_dialog("_You fools! There is no passage._ You turn and look shocked. _I killed the real Valzier months ago and took his identity. Soon I'll be a called a hero and Arivan can ignore me no longer._","_But first, you must go..._");
 set_flag(110,1,2);
 block_entry(1);
}

break;


beginstate 29;

reset_dialog();
add_dialog_str(0,"The teleporter is here. Hopefully the coordinates are correct for this appears to be your only escape.",0);
add_dialog_choice(0,"Enter.");
add_dialog_choice(1,"Stay here.");
choice = run_dialog(1);
if (choice == 1) {
 play_sound(10);
 block_entry(1);
 set_state_continue(30);
}
if (choice == 2) {
	end();
 block_entry(1); 
}

break;


beginstate 30;

force_view_center(52,29);
set_total_visibility(1);
relocate_character(36,52,27);
set_character_facing(36,4);
relocate_character(6,52,30);
set_character_facing(6,0);
relocate_character(28,50,27);
set_character_facing(28,6);
relocate_character(29,50,28);
set_character_facing(29,6);
relocate_character(30,50,29);
set_character_facing(30,6);
relocate_character(31,54,29);
set_character_facing(31,2);
relocate_character(32,54,30);
set_character_facing(32,2);
relocate_character(33,51,26);
set_character_facing(33,4);
relocate_character(34,53,26);
set_character_facing(34,4);
relocate_character(14,50,33);
set_character_facing(14,0);
relocate_character(15,53,33);
set_character_facing(15,0);
set_char_status(6,29,1,1,0);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(36,"Finally, it is over.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(36,"");
text_bubble_on_char(6,"But how?");
force_instant_terrain_redraw();
pause(10);

set_character_facing(36,0);
text_bubble_on_char(6,"");
text_bubble_on_char(36,"I have my ways.");
force_instant_terrain_redraw();
pause(20);

text_bubble_on_char(36,"");
set_character_facing(36,4);
set_character_pose(36,1);
put_boom_on_char(6,3,0);
put_stain_on_space(char_loc_x(6),char_loc_y(6),2);
set_char_status(6,29,-1,1,0);
erase_char(6);
force_instant_terrain_redraw();
run_animation_sound(54);
pause(10);

relocate_character(36,char_loc_x(36),char_loc_y(36) + 1);
set_character_pose(36,0);
force_instant_terrain_redraw();
pause(3);

relocate_character(36,char_loc_x(36),char_loc_y(36) + 1);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(36,"Pathetic...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(36,"");
force_view_center(48,49);
relocate_character(26,47,50);
set_character_facing(26,6);
relocate_character(7,49,50);
set_character_facing(7,4);
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(26,"Will this work?");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(26,"");
text_bubble_on_char(7,"I can't say.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(7,"");
text_bubble_on_char(7,"I hope it does...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(7,"");
text_bubble_on_char(7,"...for your sake.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(7,"");
play_sound(8);
force_instant_terrain_redraw();
pause(10);

relocate_character(7,char_loc_x(7) - 1,char_loc_y(7));
set_character_facing(7,2);
force_instant_terrain_redraw();
pause(3);

text_bubble_on_char(7,"Sure you want to do this?");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(7,"");
text_bubble_on_char(26,"It must be done.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(26,"");
text_bubble_on_char(7,"Well, may the gods be with you.");
force_instant_terrain_redraw();
play_sound(127);
pause(10);

text_bubble_on_char(7,"");
relocate_character(26,char_loc_x(26) + 1,char_loc_y(26) - 1);
relocate_character(36,52,27);
set_character_facing(36,4);
set_character_pose(36,0);
set_character_facing(26,7);
set_character_facing(7,0);
force_instant_terrain_redraw();
pause(5);

relocate_character(26,char_loc_x(26) + 1,char_loc_y(26) - 1);
set_character_facing(26,7);
force_instant_terrain_redraw();
pause(3);

relocate_character(26,char_loc_x(26),char_loc_y(26) - 1);
set_character_facing(26,0);
force_instant_terrain_redraw();
pause(10);

set_character_facing(26,4);
text_bubble_on_char(26,"Goodbye, friend.");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(26,"");
text_bubble_on_char(7,"...");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(7,"");
set_character_facing(26,0);
relocate_character(26,char_loc_x(26),char_loc_y(26) - 1);
force_instant_terrain_redraw();
pause(2);

relocate_character(26,char_loc_x(26),char_loc_y(26) - 1);
force_instant_terrain_redraw();
pause(2);

relocate_character(26,char_loc_x(26),char_loc_y(26) - 1);
force_instant_terrain_redraw();
pause(2);

relocate_character(26,char_loc_x(26),char_loc_y(26) - 1);
force_instant_terrain_redraw();
pause(2);

relocate_character(26,char_loc_x(26) + 1,char_loc_y(26));
set_character_facing(26,6);
force_instant_terrain_redraw();
pause(2);

relocate_character(26,char_loc_x(26) + 1,char_loc_y(26) );
force_instant_terrain_redraw();
pause(2);

erase_char(26);
force_instant_terrain_redraw();
pause(30);

play_sound(152);
play_sound(108);
play_sound(108);
play_sound(108);

text_bubble_on_char(7,"Goodbye, Klinger...");
set_character_facing(7,4);
force_instant_terrain_redraw();
pause(30);

set_flag(110,0,2);
set_total_visibility(0);
force_instant_terrain_redraw();
play_sound(10);
pause(5);

change_outdoor_location(0,1,7,28);
move_to_new_town(5,16,16);

}

break;


beginstate 31;

message_dialog("There is a wheel-like apparatus with chains that attach to the gate out front. You could use it if you really wanted, but you see no reason to make the guards upset.","");

break;


beginstate 32;

if (get_sdf(1,10) == 2) {

set_flag(1,10,3);
set_total_visibility(1);

set_terrain(18,49,384);
set_terrain(19,49,384);
set_terrain(18,53,2);
set_terrain(19,53,2);
force_view_center(19,51);
force_instant_terrain_redraw();
pause(10);

put_boom_on_space(18,50,0,0);
put_boom_on_space(19,50,0,0);
set_terrain(18,50,389);
set_terrain(18,49,388);
set_terrain(19,50,389);
set_terrain(19,49,388);
run_animation_sound(5);
force_instant_terrain_redraw();
pause(5);

set_terrain(18,53,0);
set_terrain(19,53,0);
activate_hidden_group(2);
force_instant_terrain_redraw();
play_sound(163);
pause(10);

i = 28;
while (i < 35) {
 relocate_character(i,char_loc_x(i),char_loc_y(i) - 1);
 i = i + 1;
}

force_instant_terrain_redraw();
pause(5);

i = 28;
while (i < 35) {
 relocate_character(i,char_loc_x(i),char_loc_y(i) - 1);
 i = i + 1;
}

force_instant_terrain_redraw();
pause(5);

relocate_character(0,45,28);
relocate_character(1,46,28);
relocate_character(2,47,28);
relocate_character(3,48,28);
set_character_facing(1000,0);
set_character_facing(6,4);
set_character_facing(26,4);
set_character_pose(1000,5);
force_view_center(46,28);
force_instant_terrain_redraw();
pause(5);

message_dialog("_Time is running out!_ exclaims Suvar. _We must escape now._ He points to you. _We have a special task to ask of you._","");
pause(5);

message_dialog("Klinger speaks. _There is a place called the Lost City, supposedly haunted. Within is supposed to be the source of some unnatural magical power. We believe it can be recovered and possibly used._","_In back, we have a teleportal. Fortunately, we had time to adjust the coordinates just prior to the attack. It will take you near the City. Valzier and I will accompany you._");
pause(5);

message_dialog("Suvar interrupts, _Actually, Klinger, I have considered the matters and we need you to help establish the alternate base. Afterward, you will go out to the Lost City and recover them._","");
pause(5);

message_dialog("_Understood, chieftain._ Klinger nods.","");
pause(5);

message_dialog("_Valzier already knows where the teleporter is. He will lead you there. Meanwhile, we must take the alternate route. Follow him and take haste. If all goes well, we will meet again._","");
pause(5);

spawn_creature(38);
add_char_to_party(38);
erase_char(38);
erase_char(27);
teleport_party(58,20,1);
relocate_character(0,58,20);
relocate_character(1,58,21);
relocate_character(2,58,22);
relocate_character(3,58,23);
relocate_character(4,58,24);
set_character_pose(1000,0);
set_character_facing(1000,0);
force_view_center(58,20);
force_instant_terrain_redraw();
pause(5);

i = 0;
while (i < 5) {
 relocate_character(i,char_loc_x(i),char_loc_y(i) - 1);
 i = i + 1;
}

force_view_center(58,19);
force_instant_terrain_redraw();
pause(5);

set_character_facing(4,4);
force_instant_terrain_redraw();
pause(5);

set_character_pose(4,1);
put_effect_on_space(char_loc_x(4),char_loc_y(4) + 1,9,4,1);
set_terrain(char_loc_x(4),char_loc_y(4) + 1,270);
force_instant_terrain_redraw();
run_animation_sound(109);
pause(5);

text_bubble_on_char(4,"That should hold them.");
set_character_pose(4,0);
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(4,"");
text_bubble_on_char(4,"Let's go!");
set_character_facing(4,4);
force_instant_terrain_redraw();
pause(5);

set_flag(110,1,1);

text_bubble_on_char(4,"");
toggle_quest(4,1);
set_total_visibility(0);

}

break;
